package com.gko100.dao.impl;

import java.util.List;

import com.gko100.dao.NavigationDao;
import com.gko100.dao.basehibernatesupport.BaseHibernateDaoSupport;
import com.gko100.model.Category;
import com.gko100.model.Language;
import com.gko100.model.Navigation;

public class NavigationDaoHibernate extends BaseHibernateDaoSupport implements NavigationDao {

	
	public void delNav(Navigation nav) {
		
		this.getHibernateTemplate().delete(nav);
		
	}

	public void delNavByNavId(Integer navId) {
		
		this.getHibernateTemplate().delete(this.findNavByNavId(navId));
		
	}


	public List<Navigation> findNavListByCate(Category cate){
		
		List<Navigation> navList = this.getHibernateTemplate().find("from Navigation as n where n.cate=?", cate);
		if(navList!=null&&navList.size()>=1){
			return navList;
		}else{
			
			return null;
		}
	}
	
	public Navigation findNavByNavNote(String navNote){
		
		List<Navigation> navList = this.getHibernateTemplate().find("from Navigation as n where n.navNote=?",navNote);
		
		if(navList!=null&&navList.size()>=1){
			return navList.get(0);
		}else{
			return null;
		}
	}
	
	public Navigation findNavByCate(Category cate){
		
		List<Navigation> navList = this.getHibernateTemplate().find("from Navigation as n where n.cate=?", cate);
		if(navList!=null&&navList.size()>=1){
			return navList.get(0);
		}else{
			
			return null;
		}
	}
	
	public Navigation findNavByNavId(Integer navId) {
		
		Navigation nav=this.getHibernateTemplate().get(Navigation.class, navId);
		if(nav!=null){
			return nav;
		}else{
			
			return null;
		}
		
	}
	
	public List<Navigation> findNavByLangAndCate(Language lang, Category cate){
		
		List<Navigation> navList = this.getHibernateTemplate().find("from Navigation as n where n.lang=? and n.cate=?", lang, cate);
		if(navList!=null&&navList.size()>=1){
			return navList;
		}else{
			
			return null;
		}
		
	}
	
	public List<Navigation> findNavListByNavPid(Integer navPid){
		
		List<Navigation> navList = this.getHibernateTemplate().find("from Navigation as n where n.navPid=?",navPid);
		if(navList!=null&&navList.size()>=1){
			return navList;
		}else{
			
			return null;
		}
	}

	public List<Navigation> findNavListByNavPIdAndLang(Integer navPid,Language lang){
		
	
		List<Navigation> navList = this.getHibernateTemplate().find("from Navigation as n where n.navPid=? and n.lang=?",navPid,lang);
		
		if(navList!=null&&navList.size()>=1){
			return navList;
		}else{
			
			return null;
		}
		
		
	}
	
	public Navigation findNavByNavName(String navName) {
		
		List<Navigation> navList=this.getHibernateTemplate().find("from Navigation as n where n.navName=?",navName);
		if(navList!=null&&navList.size()>=1){
			return navList.get(0);
		}else{
			
			return null;
		}
	}

	public Integer[] findNavIdListByNavPid(Integer navPid){
		
		List<Navigation> navList = this.getHibernateTemplate().find("from Navigation as n where n.navPid=?",navPid);
		Integer[] navIdList = null;
		if(navList!=null&&navList.size()>=1){
			for(int i=0;i<navList.size();i++){
				navIdList[i]=navList.get(i).getNavId();
			}
			return navIdList;
		}else{
			
			return null;
		}
	}

	public void saveNav(Navigation nav) {
		
		this.getHibernateTemplate().save(nav);
		
	}

	public void updateNav(Navigation nav) {
		
		this.getHibernateTemplate().update(nav);
		
	}

}
